<template>
<div class="all" ref="box">
  <header>
    <div class="div" @click="back">
      <img src="../../../assets/返回.png" alt="">
      <span class="solid">返回</span>
    </div>
    <div class="div">
      <span>选择团队/机构</span>
    </div>
    <div class="div"></div>
  </header>
  <div class="box"
       @click="clickBox(item)"
       v-for="(item, index) in teamList" :key="index" :class="selectTeamID == item.id ? 'select' : ''">
    <div class="box_left">
      <img v-if="item.team_icon !== '' && item.team_icon !== undefined && item.team_icon !== null"
           :src="item.team_icon" class="PHOTO" alt="">
      <img v-else src="../../../assets/男医生@2x.png" class="PHOTO" alt="">
    </div>
    <div class="box_right">
      <ul>
        <li>
            <span class="name">
              {{item.team_name}}
              <a style="font-size: 13px;font-weight: 500">（{{item.count}}人）</a>
            </span>
          <span v-show="Number(item.shenqing) === 1" style="color: #1da4f2">申请中</span>
        </li>
        <li>
          <span >团队长：{{item.NICK_NAME}}</span>
          &nbsp;
          &nbsp;
          &nbsp;
<!--          <span>团队人数：{{item.count}}人</span>-->
          <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
          <span>&nbsp;|&nbsp;</span>
          <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
        </li>
<!--        <li>-->
<!--          <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>-->
<!--          <span>|</span>-->
<!--          <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>-->
<!--        </li>-->
        <li>
          <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
          <button class="biaoqian">{{item.GRADE}}</button>
        </li>
      </ul>
<!--      <div class="box_rigth_bottom">
        <p>
          <a >接诊率:</a>
          <span v-if=" item.jiezhenCount!== undefined && item.jiezhenCount!== null && item.jiezhenCount!== ''">{{item.jiezhenCount}}</span>
          <span v-else>暂无</span>
          <a >好评率:</a>
          <span v-if=" item.haopingLv!== undefined && item.haopingLv!== null && item.haopingLv!== ''">{{item.haopingLv}}</span>
          <span v-else>暂无</span>
          <a >咨询量:</a>
          <span v-if=" item.zixunCount!== undefined && item.zixunCount!== null && item.zixunCount!== ''">{{item.zixunCount}}</span>
          <span v-else>暂无</span>
        </p>
        <p class="goodAt">
          <a style="display: block">擅长:</a>
          <span>{{item.team_goodat}}</span>
        </p>
        <p>
          <a >最快回复:</a>
          <span style="color: #1DA4F2"  v-if="item.min !== undefined && item.min !== null && item.min !== ''">{{item.min}}</span>
          <span v-else style="color: #999999">暂无</span>
          <a >平均回复:</a>
          <span style="color: #1DA4F2" v-if="item.avg !== undefined && item.avg !== null && item.avg !== ''">{{item.avg}}</span>
          <span style="color: #999999" v-else>暂无</span>
        </p>
      </div>-->
    </div>
  </div>
  <van-loading v-show="isLoading" size="24px" style="width: 100%;height: 80%;
    display:flex;align-items:center;justify-content:center; color: #1da4f2" vertical>
    加载中...
  </van-loading>
  <van-empty
    style="width: 100%;height: 60%"
    v-show="teamList.length <= 0 && isLoading === false"
    class="custom-image"
    :image="require('../../../assets/空两本书.png')"
    description="暂无选择团队/机构"
  />
</div>
</template>

<script>
export default {
  name: 'SelectTeamOrOrgan',
  data () {
    return {
      teamList: [],
      page: 1,
      isScroll: true,
      isLoading: true,
      userid: this.$route.query.userid,
      selectTeamID: ''
    }
  },
  mounted () {
    if (sessionStorage.getItem('TeamOrganCode')) {
      let data = JSON.parse(sessionStorage.getItem('TeamOrganCode'))
      this.selectTeamID = data.team_id
    }
    this.getTeamList()
    window.addEventListener('scroll', this.scrollBottom, true)
  },
  methods: {
    // 滚动事件
    scrollBottom () {
      let scrollTop = this.$refs.box.scrollTop
      let clientHeight = this.$refs.box.clientHeight
      let scrollHeight = this.$refs.box.scrollHeight
      if (scrollHeight - scrollTop <= clientHeight + 300 && this.isScroll === true) {
        this.isScroll = false
        setTimeout(() => {
          this.page += 1
          this.isLoading = true
          // 移除滚动事件
          window.removeEventListener('scroll', this.scrollBottom, true)
          this.getTeamList()
        }, 500)
      }
    },
    clickBox (item) {
      let data = new Object()
      if (sessionStorage.getItem('TeamOrganCode')) {
        data = JSON.parse(sessionStorage.getItem('TeamOrganCode'))
      }
      data.team_id = item.id
      sessionStorage.setItem('TeamOrganCode', JSON.stringify(data))
      this.$router.push({path: '/SelectTeamMembers', query: {userid: this.userid, team_id: item.id, team_name: item.team_name}})
    },
    getTeamList () {
      this.isLoading = true
      this.$http.TeamList({page: this.page, team_type: 4})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            var _this = this
            if (Number(this.page) === 1) {
              this.teamList = []
              this.teamList = res.data.data
            } else {
              res.data.data.forEach(function (current, index, arr) {
                _this.teamList.push(current)
              })
            }
            if (res.data.data.length > 0) {
              window.addEventListener('scroll', this.scrollBottom, true)
              this.isScroll = true
            } else {
              window.removeEventListener('scroll', this.scrollBottom, true)
              this.isScroll = false
            }
            this.isLoading = false
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  },
  destroyed () {
    window.removeEventListener('scroll', this.scrollBottom, true)
  }
}
</script>

<style scoped>
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  width: 33%;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  margin-right: 15px;
}
.div:nth-child(2){
  justify-content: center;
}
.div:nth-child(3){
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.box{
  padding: 10px;
  box-sizing: border-box;
  background: white;
  margin-bottom: 8px;
  display: flex;
}
.all .box:last-of-type{
  margin-bottom: 60px;
}
.PHOTO{
  width: 55px;
  height: 55px;
  border-radius: 50%;
  object-fit: cover;
}
.box_left{
  width: 23%;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: space-between;
}
.dict_name{
  font-size: 11px;
  border: 1px solid #1DA4F2;
  border-radius: 2px;
  background: rgba(16, 184, 246, 0.1);
  color: #1da4f2;
  padding: 1px 3px;
  box-sizing: border-box;
  white-space: nowrap;
  /*margin-top: 10px;*/
}
.box_right{
  width: 78%;
}
.box_right ul{
  /*height: 60px;*/
  display: flex;
  flex-direction: column;
  align-content: space-around;
  justify-content: space-around;
}
.box_right ul li{
  display: flex;
  align-items: center;
  font-size: 13px;
  font-family: PingFang SC;
  min-height: 25px;
}
.box_right ul li:nth-child(1){
  justify-content: space-between;
}
.name{
  font-size: 15px!important;
  font-weight: bold;
  color: #333333;
}
.biaoqian{
  /*padding: 0px 8px;*/
  min-width: 44px;
  height: 18px;
  border-radius: 15px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  /* background: rgba(29, 164, 242, 0.1); */
  background: transparent;
  color: #1DA4F2;
  /* border: none; */
  border: 1px solid;
  font-size: 11px;
  margin-left: 8px;
}
.btnXiangQing{
  color: white;
  background: #1DA4F2;
  border: none;
  padding: 3px 8px;
  border-radius: 2px;
  box-sizing: border-box;
  font-size: 11px;
}
.btnXiangQing img{
  width: 5px;
  height: 9px;
  margin-left: 5px;
}

.btnXiangQing,
.biaoqian,
.jieShao
{
  display: flex;
  align-items: center;
  justify-content: center;
}
.jieShao{
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
  margin-right: 8px;
}
.box_rigth_bottom{
  margin-top: 5px;
}
.box_rigth_bottom p{
  margin-bottom: 5px;
}
.box_rigth_bottom p:nth-child(1),
.box_rigth_bottom p:nth-child(3){
  font-size: 13px;
}
.box_rigth_bottom p a{
}
.box_rigth_bottom p span{
  color: #E3170D;
  margin: 0 8px 0 3px;
}
.goodAt{
  font-size: 13px;
  display: flex;
}
.goodAt a{
  display: block;
  white-space: nowrap;
}
.goodAt span{
  /*width: 80%;*/
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #333 !important;
}
.select{
  background: rgba(29, 164, 242, 0.2);
}
</style>
